package sql_age;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Student implements Writable, DBWritable {
    private int id;
    private int sid;
    private String name;
    private int age;
    private String sex;
    private String birthday;

    public void write(DataOutput out) throws IOException {
        out.writeInt(this.id);
        out.writeInt(this.sid);
        out.writeUTF(this.name);
        out.writeInt(this.age);
        out.writeUTF(this.sex);
        out.writeUTF(this.birthday);
    }


    public void readFields(DataInput in) throws IOException {
        this.id = in.readInt();
        this.sid = in.readInt();
        this.name = in.readUTF();
        this.age = in.readInt();
        this.sex = in.readUTF();
        this.birthday = in.readUTF();
    }


    public void write(PreparedStatement statement) throws SQLException {
        statement.setInt(1, this.id);
        statement.setInt(2, this.sid);
        statement.setString(3, this.name);
        statement.setInt(4, this.age);
        statement.setString(5, this.sex);
        statement.setString(6, this.birthday);
    }


    public void readFields(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getInt(1);
        this.sid = resultSet.getInt(2);
        this.name = resultSet.getString(3);
        this.age = resultSet.getInt(4);
        this.sex = resultSet.getString(5);
        this.birthday = resultSet.getString(6);
    }

    public int getStudent_id() {
        return sid;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getSex() {
        return sex;
    }
}
